package com.college.resource.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.college.common.pojo.ao.CarouselImage;
import com.college.common.pojo.ao.CarouselImage;
import com.college.common.pojo.dto.resource.AddCarouselImageDTO;
import com.college.common.pojo.dto.resource.QueryCarouselImageDTO;
import com.college.common.pojo.dto.resource.UpdateCarouselImageDTO;
import com.college.common.pojo.model.page.PageParamRequest;
import com.college.common.response.CommonResult;
import com.college.common.utils.object.ObjectUtil;
import com.college.resource.mapper.CarouselImageMapper;
import com.college.resource.service.CarouselImageService;
import com.github.pagehelper.page.PageMethod;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 轮播图 服务实现类
 * </p>
 *
 * @author 小C工作室
 * @since 2025-02-22
 */
@Service
public class CarouselImageServiceImpl extends ServiceImpl<CarouselImageMapper, CarouselImage> implements CarouselImageService {
    @Autowired
    private CarouselImageMapper carouselImageMapper;

    @Override
    public List<CarouselImage> queryList(QueryCarouselImageDTO queryCarouselImageDTO) {
        return carouselImageMapper.queryList(queryCarouselImageDTO);
    }

    @Override
    public List<CarouselImage> queryListPage(QueryCarouselImageDTO queryCarouselImageDTO, PageParamRequest pageParamRequest) {
        PageMethod.startPage(pageParamRequest.getPage(), pageParamRequest.getLimit());
        return carouselImageMapper.queryList(queryCarouselImageDTO);
    }

    @Override
    public CommonResult<String> addCarouselImage(AddCarouselImageDTO addCarouselImageDTO) {
        return this.save(addCarouselImageDTO)? CommonResult.success("轮播图新增成功") : CommonResult.failed("轮播图新增失败");
    }

    @Override
    public CommonResult<String> updateCarouselImage(UpdateCarouselImageDTO updateCarouselImageDTO) {
        CarouselImage carouselImage = ObjectUtil.objectCopyProperties(updateCarouselImageDTO, CarouselImage.class);
        return this.updateById(carouselImage) ? CommonResult.success("轮播图修改成功") : CommonResult.failed("轮播图修改失败");
    }
}
